import {Vue} from "vue/types/vue";

export default class AppMain {
  public app: Vue;
  public constructor( app: Vue ) {
    this.app = app;
    const ua: any = window.navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i)) {
      this.jumpAuth();
    } else {
      // 自动登录
      this.autoLogin();
    }
  }

  // 自动登录
  public autoLogin() {
    // this.app.$store.dispatch("Account/isLogin");
  }
  // 跳转授权
  public jumpAuth() {
    let origin = encodeURIComponent(location.origin);
    if ( /share\/product\/(.*)/.test(location.pathname) ) {
      origin += location.pathname;
    }
    if ( /product\/detail\/(.*)/.test(location.pathname) ) {
      origin += location.pathname;
    }
    if (/\?userId=/.test(location.search)) {
      origin += location.search;
    }
    if ( localStorage.getItem("wx_code") ) {
      localStorage.removeItem("wx_code");
      return true;
    }
  }
}
